package com.wzl.mixed.service.impl;

import com.wzl.common.errcode.VkErrorCodeEnum;
import com.wzl.common.exception.VkPublicException;
import com.wzl.mixed.service.MpTryCatchSevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author weizhongli
 * @since 1.0, 2022/11/15 10:37
 */
@Service
@Slf4j
public class MpTryCatchServiceImpl implements MpTryCatchSevice {

    @Override
    public void getMssage1() throws VkPublicException {
        try {
            queryUser1();
        } catch (VkPublicException e) {
            log.error("中间VkPublicException报错啦");
            throw e;
        } catch (Exception e) {
            log.error("中间Exception报错啦");
            throw new VkPublicException(VkErrorCodeEnum.ERROR_ARRAY_INDEX_OUT_OF_BOUNDS);
        }
    }
    public int queryUser1() throws VkPublicException{
        try {
            return 1/0;
        } catch (Exception e) {
            log.error("最内层报错啦");
            throw new VkPublicException(VkErrorCodeEnum.QURRY_MESSAGE_ERROR,e);
        }
    }



    @Override
    public void getMssage2() throws VkPublicException {
        try {
            int a = 1/0;
            queryUser2();
            //int a = 1/0;
        } catch (VkPublicException e) {
            log.error("中间VkPublicException报错啦");
            throw e;
        } catch (Exception e) {
            log.error("中间Exception报错啦");
            throw new VkPublicException(VkErrorCodeEnum.ERROR_ARRAY_INDEX_OUT_OF_BOUNDS);
        }
    }
    public int queryUser2() throws VkPublicException{
        try {
            return 1/1;
        } catch (Exception e) {
            log.error("最内层报错啦");
            throw new VkPublicException(VkErrorCodeEnum.QURRY_MESSAGE_ERROR,e);
        }
    }

}